#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
#include <string>


//年终奖
//https://www.nowcoder.com/questionTerminal/72a99e28381a407991f2c96d8cb238ab
//class Bonus {
//public:
//    int getPrize(const vector<vector<int>>& board, int i, int k)
//    {
//        if (i + 1 == board.size() && k + 1 ==  board[i].size())
//        {
//            return board[i][k];
//        }
//        else if (i + 1 < board.size() && k + 1 == board[i].size())
//        {
//            return board[i][k] + getPrize(board, i + 1, k);
//            
//        }
//        else if (i + 1 == board.size() && k + 1 < board[i].size())
//        {
//            return board[i][k] + getPrize(board, i, k + 1);
//        }
//
//        return board[i][k] + max(getPrize(board, i + 1, k), getPrize(board, i, k + 1));
//    }
//    int getMost(vector<vector<int>> board) 
//    {
//        return getPrize(board, 0, 0);
//    }
//};

//迷宫问题 - 未完成，通过90%
// https://www.nowcoder.com/questionTerminal/cf24906056f4488c9ddb132f317e03bc

//迷宫问题 - 回溯算法学习
int L = 0;
int R = 0;
vector<vector<int>> pathtmp;
vector<vector<int>> path;
vector<vector<int>> vv;

void getpath(int l, int r)
{
    vv[l][r] = 1;
    pathtmp.push_back({ l,r });

    if (l == L - 1 && r == R - 1)
    {
        if (path.empty() || path.size() > pathtmp.size())
        {
            path = pathtmp;
        }
    }

    if (l + 1 < L && vv[l + 1][r] == 0)
        getpath(l + 1, r);

    if (r + 1 < R && vv[l][r + 1] == 0)
        getpath(l, r + 1);

    if (l - 1 >= 0 && vv[l - 1][r] == 0)
        getpath(l - 1, r);

    if (r - 1 >= 0 && vv[l][r - 1] == 0)
        getpath(l, r - 1);

    vv[l][r] == 0;
    pathtmp.pop_back();
}

int main() {
    while (cin >> L >> R) {

        vv.clear();
        vv.resize(L, vector<int>(R, 0));
        for (int i = 0; i < L; ++i) {
            for (int k = 0; k < R; ++k) {
                cin >> vv[i][k];
            }
        }

        path.clear();
        pathtmp.clear();
        getpath(0, 0);

        for (int i = 0; i < path.size(); ++i)
        {
            printf("(%d,%d)\n", path[i][0], path[i][1]);
        }
    }
}